/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controlstudent.datos;

import com.controlstudent.entidades.Curso;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Neil
 */
public class CursoDAO {

    private static CursoDAO instance = null;

    private CursoDAO() {
    }

    public static CursoDAO getInstance() {
        if (instance == null) {
            instance = new CursoDAO();
        }
        return instance;
    }

    public ArrayList<Curso> listarcursos() {
        ArrayList<Curso> cursos = null;
        Connection cn = null;

        String sql = "select curs_id, curs_des from curso";

        try {
            cursos = new ArrayList<>();
            cn = ConnectionManager.getConnection();
            PreparedStatement ps = cn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Curso c = new Curso();
                c.setId_curso(rs.getInt("curs_id"));
                c.setDesc_curso(rs.getString("curs_des"));
                cursos.add(c);
            }
        } catch (Exception e) {
        } finally {
            try {
                cn.close();
            } catch (SQLException ex) {
            }
        }
        return cursos;
    }

}
